from django.conf import settings
from django.http import HttpResponse
from django.utils.importlib import import_module
from django.template import loader, Context, RequestContext
from django.shortcuts import render_to_response
from models import ImageItem, PixelPosition
from django.utils import simplejson

def introduction(request):
    t = loader.get_template('introduction.html')    
    rc = RequestContext(request, {})
    return HttpResponse(t.render(rc))    

def sphere(request):
	t = loader.get_template('sphere.html') 
	rc = RequestContext(request, {})       
	return HttpResponse(t.render(rc))
	#return render_to_response('sphere.html', {})
	
def practice_s1(request):
	t = loader.get_template('praticeS1.html') 
	rc = RequestContext(request, {})       
	return HttpResponse(t.render(rc))
	
def practice_sphere(request):
	t = loader.get_template('praticeSphere.html') 
	rc = RequestContext(request, {})       
	return HttpResponse(t.render(rc))
	
	
def experimentImageName(request, imageName):
	imageItem = ImageItem.objects.filter( name = "sphere.png")
	data = {}
	if imageItem and len(imageItem) == 1:		
		data['depthOffset'] = imageItem[0].depthOffset
		data['depthResize'] = imageItem[0].depthResize
		data['focalLength'] = imageItem[0].focalLength
		data['sensorWidth'] = imageItem[0].sensorWidth
		
		#pixels = PixelPosition.objects.filter( imageItem = imageItem).order_by('xPos')
		pixels = PixelPosition.objects.all()		
		'''
		xPos = models.IntegerField()
		yPos = models.IntegerField()
		depth = models.FloatField()
		normalX = models.FloatField()
		normalY = models.FloatField()
		normalZ = models.FloatField()
		'''
		positionNormals = []
		for pix in pixels:
			pn = []
			pn.append(pix.xPos)
			pn.append(pix.yPos)
			pn.append(pix.depth)
			pn.append(pix.normalX)
			pn.append(pix.normalY)
			pn.append(pix.normalZ)
			positionNormals.append(pn)
		data['positionNormals']  = positionNormals
		
		t = loader.get_template('gaugeExperiment.html') 
		rc = RequestContext(request, data)	
		
	else:
		#report error
		t = loader.get_template('introduction.html') 
		rc = RequestContext(request, {})	       
	return HttpResponse(t.render(rc))

	
	
    
